<?php
/*
	插件概览
*/
global $_RQ,$_AR;
$merchid=$this->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
$setting = $this->plugin_setting('setting');
$return['types']=array(
	'1'=>'普通订阅号',
	'2'=>'认证订阅号',
	'3'=>'普通服务号',
	'4'=>'认证服务号'
);
if($_RQ['op']=='edit'){
	$item=pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid));
    $return['plugin_icon']=$item['logo'];
	$item['lat_lng']=$item['lat_lng']?json_decode($item['lat_lng'],true):array();
	$item['codeimg']=$item['codeimg']?json_decode($item['codeimg'],true):array();
	$item['pcd']=$item['pcd']?json_decode($item['pcd'],true):array('province'=>'');
	if(!$item['pcd']['province']){
		$item['pcd']=array('province'=>'');
	}
	$item['onlinetime']=json_decode($item['onlinetime'],true);
	if(strpos($item['diyformdata'],'title') !== false){
		$item['diyfields']=json_decode($item['diyformdata'],true);
	}else{
		$item['diyfields']=$setting['diyformfields'];
	}
	$item['items']=$item['items']?json_decode($item['items'],true):array();
	$item['setting']=$item['setting']?json_decode($item['setting'],true):array();
	$item['sets']=$item['sets']?json_decode($item['sets'],true):array('red'=>0);
	//$item['datamids']=json_decode($item['datamids'],true);
	$item['myshop_tpl']=$item['myshop_tpl']?:0;
	$item['onecredit']=$item['onecredit']?json_decode($item['onecredit'],true):array('credit3'=>1);
	if($item['onewechat']){
		$item['onewechat']=json_decode($item['onewechat'],true);
		if(!$item['onewechat']['token']){
			$item['onewechat']=array('isopen'=>0);
		}
	}else{
		$item['onewechat']=array('isopen'=>0);
	}
	$item['url']=SITEROOT.'addons/jy_merch/wxapi.php?merchid='.$item['id'];
	$item['onewechat']['token']=$item['onewechat']['token']?:random(30);
	$item['onewechat']['aeskey']=$item['onewechat']['aeskey']?:random(43);
	$item['app']=$item['app']?json_decode($item['app'],true):array('isopen'=>0);
	$item['appurl']=custom_url('jy_merch/getapp//merchid='.$item['id'],true);
	$item['app']['installbak']=tomedia($item['app']['installbak']);
	$item['cert_file']=$item['onewechat']['cert_file'];
	$item['key_file']=$item['onewechat']['key_file'];
	$account_host=get_account_url();
	$account_tp=str_replace('http://','',$account_host).'custom/';
	$account_apitp=str_replace('http://','',$account_host).'app/';
	$account_url=str_replace('http://','',$account_host).'custom/payresult/wechat_notify.php';
	$return['status']=array('1'=>'开启','0'=>'关闭');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'商城设置',
		'edit_tab'=>true,
		'edits'=>array(
				array(
					'title'=>'基本信息',
					'list'=>array(
							array('name'=>'type','title'=>'商户类型','type'=>'radio','options'=>'merch_type'),
							array('type'=>'string','must'=>true,'title'=>'商城名称','name'=>'merchname'),
							array('type'=>'image','title'=>'商城logo','name'=>'logo'),
							array('type'=>'text','title'=>'商城简介','name'=>'desc'),
							array('type'=>'text','title'=>'商户公告','name'=>'remark'),
							array('type'=>'string','title'=>'主营项目','name'=>'salecate'),
							array('name'=>'cateid','must'=>true,'title'=>'商户分类','type'=>'select','options'=>'cate','option_title'=>'catename'),
							array('type'=>'string','title'=>'小店联系人','name'=>'realname'),
							array('type'=>'string','title'=>'小店手机','name'=>'mobile'),
							array('type'=>'pcd','title'=>'小店区域','name'=>'pcd'),
							array('type'=>'string','title'=>'小店地址','name'=>'address'),
							array('type'=>'lat_lng','must'=>true,'title'=>'小店坐标','name'=>'lat_lng'),
							array('name'=>'offline','title'=>'休息?','type'=>'switch'),
							array('type'=>'time_hour','title'=>'营业时间','name'=>'onlinetime','show'=>array('type'=>1)),
							//array('name'=>'datamids','title'=>'选择操作员','type'=>'choose_many','action'=>'core/member.get_member/many','help'=>'只有查看商户数据的权限！'),	

							array('type'=>'image','title'=>'店招','name'=>'topimg'),
							array('name'=>'tel','title'=>'商户电话','type'=>'string'),
							array('name'=>'sendtype','title'=>'默认配送方式','type'=>'radio','options'=>'sendtypes'),

							array('name'=>'mypeisong','title'=>'是否自己配送','type'=>'switch','help'=>'不开启，则由平台配送员统一配送！','show'=>array('type'=>1)),
							array('type'=>'switch','title'=>'需要制作？','name'=>'ismake','help'=>'开启后，商户有需要制作的过程，制作完成后，后台点发货，配送员才能接单！'),
							array('name'=>'out_pay','title'=>'配送费','type'=>'string','help'=>'开启《自己配送》后才生效，否则是由系统配送员配送，费用也是由系统决定','show'=>array('type'=>1)),
							array('name'=>'out_price','title'=>'起送金额','type'=>'string','show'=>array('type'=>1)),
							array('name'=>'man_fee','title'=>'满额免配送费','type'=>'string','help'=>'开启《自己配送》后才生效，否则是由系统配送员配送，费用也是由系统决定','show'=>array('type'=>1)),
							array('name'=>'out_juli','title'=>'最大配送距离','type'=>'unitstring','unit'=>'KM','help'=>'留空则由平台统一','show'=>array('type'=>1)),
							array('name'=>'out_upfee','title'=>'打包费','type'=>'unitstring','unit'=>'元','help'=>'留空则为0！','show'=>array('type'=>1)),
							array('name'=>'payopenid','title'=>'选择收款人','type'=>'choose_title','action'=>'get_member'),	
							array('type'=>'switch','title'=>'开启客服','name'=>'iskefu','help'=>'开启客服后，会进入客服界面，没开启，点击拨打客服电话！'),
							array('type'=>'switch','title'=>'支持分销','name'=>'iscommission','help'=>'支持分销后，别的商户，可以选择添加您的商品到自己的小店，客户购买后享受佣金（佣金比例跟《微客分销》参数保持一致）！'),
							array('type'=>'string','title'=>'可被复制','name'=>'is_share','help'=>'开启可复制后,他人可以一键复制你的店铺商品,店铺LOGO,描述等！'),
							array('name'=>'codeimg','title'=>'营业执照/许可证','type'=>'images'),
							array('name'=>'content','title'=>'商户详情','type'=>'richtext'),
							
					)
				),
				array(
					'title'=>'店铺风格设置',
					'list'=>array(
						array('type'=>'tip','title'=>'【温馨提示】：默认是“基本设置”已经指定了店铺风格。本小店设置的风格优先生效！'),
						array('type'=>'radio_tpl','title'=>'我的小店显示风格','name'=>'myshop_tpl','options'=>'myshop_tpls'),
					)
				),
				array(
					'title'=>'现金红包',
					'list'=>array(
						array('type'=>'unitstring','unit'=>'%','name'=>'sets.red_rate','title'=>'会员下单红包返现比例'),
						//array('type'=>'unitstring','unit'=>'%','name'=>'sets.ti_max','title'=>'每天可提现最大红包','help'=>'金额再1~最大的金额，随机获取红包到零钱，一天只能零钱一次'),
					)
			),
			)
	);
	if($this->setting['isone_wechat']){
		$htmls['edits'][]=array(
				'title'=>'独立微信支付',
				'list'=>array(
					array('type'=>'tip','title'=>'【<red>温馨提示</red>】：
					</br>1、一定要在微信支付商户后台配送好微信支付的回调域名，否则不能正常支付回调！
					<br>2、JSAPI支付授权目录：'.$account_tp.'，兼容插件支付授权目录：'.$account_apitp.'
					<br>3、扫码回调链接：'.$account_url.'
					<br>4、微信支付商户的密钥不对，也可能导致支付回调异常（支付成功后：可能订单状态还是未支付）。'
					),
					array('type'=>'switch','title'=>'开启独立微信支付？','name'=>'onewechat.isopen','help'=>'开启后，商户可以设置自己的微信公众号，微信支付商户等！'),	
					array('type'=>'radio','title'=>'公众号类型','name'=>'onewechat.type', 'options'=>'types','help'=>'请设置正确的公众号类型，以免出错！(非认证服务号，可以借用系统认证服务号权限，否则无法微信一键登录，获取粉丝信息等；如果是认证服务号，需移步《微信公众号平台》--》接口设置--》网页授权回调域名，设置好域名才能正常使用！)'),
					array('type'=>'string','title'=>'AppID','name'=>'onewechat.appid','help'=>'填写公众号开发者AppID。登陆微信公众平台——开发——基本配置——开发者ID'),
					array('type'=>'string','title'=>'AppSecre','name'=>'onewechat.appsecret','help'=>'填写公众号开发者AppSecret。登陆微信公众平台——开发——基本配置——开发者密钥'),
					array('type'=>'string','title'=>'原始ID','name'=>'onewechat.oldid','help'=>'填写公众号原始ID。登陆微信公众平台——设置——公众号设置——帐号详情——原始ID'),
					array('type'=>'string','title'=>'微信支付商户号','name'=>'onewechat.wechat_mchid'),
					array('type'=>'string','title'=>'商户支付密钥','name'=>'onewechat.wechat_miyue','help'=>'如果是服务商支付，此处填写服务商支付密钥'),
					array('type'=>'upfile','title'=>'CRET证书文件'.$cert_remark,'name'=>'cert_file','help'=>'下载证书 cert.zip 解压后，上传 apiclient-cert.pem 文件。'),
					array('type'=>'upfile','title'=>'KEY密钥文件'.$key_remark,'name'=>'key_file','help'=>'下载证书 cert.zip  解压后，上传 apiclient-key.pem 文件。'),	
					array('type'=>'tip','title'=>'公众号绑定方法（授权模式添加公众号请忽略此步骤）：根据提示填写上述参数之后，将以下三项参数填至微信公众平台——开发——基本配置——服务器配置，启用，提交即可。'),
					array('type'=>'tip','title'=>'<red>[token验证失败?]:如果是https的：微信目前HTTPS他是有安全门槛的，达不到ATS安全标准证书或SSL证书安装不规范，就算安装了HTTPS也是不会通过微信认证；如果是其他原因，可以百度搜索一下自行排查。</red>' ),
					array('type'=>'copy','title'=>'服务器地址','name'=>'url', 'help'=>'' ),
					array('type'=>'copy','title'=>'令牌（Token）','name'=>'onewechat.token','help'=>'' ),
					array('type'=>'copy','title'=>'消息加解密密钥(EncodingAESKey)','name'=>'onewechat.aeskey','help'=>''),
				)
		);
	}
	if($this->setting['isone_credit']){
		$htmls['edits'][]=array(
				'title'=>'独立虚拟币支付',
				'list'=>array(
					array('type'=>'radio','title'=>'开启金币交易','name'=>'onecredit.credit3','options'=>'credit_status'),
					//array('type'=>'string','title'=>'金币重命名','name'=>'onecredit.credit3_title'),
					array('type'=>'string','title'=>'金币交易抵扣比例','name'=>'onecredit.credit3_rate','help'=>'默认1：1交易，填10表示：10：1交易（10个抵扣1元）'),
					array('type'=>'unitstring','unit'=>'%','title'=>'最大抵现比例','name'=>'onecredit.credit3_dirate','help'=>'默认100%抵扣，如果填写50，表示最大抵扣订单额度的50%'),
					array('type'=>'radio','title'=>'开启元宝交易','name'=>'onecredit.credit4','options'=>'credit_status'),
					//array('type'=>'string','title'=>'元宝重命名','name'=>'onecredit.credit4_title'),
					array('type'=>'string','title'=>'元宝交易抵扣比例','name'=>'onecredit.credit4_rate','help'=>'默认1：1交易，填10表示：10：1交易（10个抵扣1元）'),
					array('type'=>'unitstring','unit'=>'%','title'=>'最大抵现比例','name'=>'onecredit.credit4_dirate','help'=>'默认100%抵扣，如果填写50，表示最大抵扣订单额度的50%'),
					array('type'=>'radio','title'=>'开启备用金交易','name'=>'onecredit.credit5','options'=>'credit_status'),
					//array('type'=>'string','title'=>'备用金重命名','name'=>'onecredit.credit5_title'),
					array('type'=>'string','title'=>'备用金交易抵扣比例','name'=>'onecredit.credit5_rate','help'=>'默认1：1交易，填10表示：10：1交易（10个抵扣1元）'),
					array('type'=>'unitstring','unit'=>'%','title'=>'最大抵现比例','name'=>'onecredit.credit5_dirate','help'=>'默认100%抵扣，如果填写50，表示最大抵扣订单额度的50%'),
					array('type'=>'radio','title'=>'开启R币交易','name'=>'onecredit.credit6','options'=>'credit_status'),
					//array('type'=>'string','title'=>'R币重命名','name'=>'onecredit.credit6_title'),
					array('type'=>'string','title'=>'R币交易抵扣比例','name'=>'onecredit.credit6_rate','help'=>'默认1：1交易，填10表示：10：1交易（10个抵扣1元）'),
					array('type'=>'unitstring','unit'=>'%','title'=>'最大抵现比例','name'=>'onecredit.credit6_dirate','help'=>'默认100%抵扣，如果填写50，表示最大抵扣订单额度的50%'),
				)
		);
	}
	if($this->setting['isone_app']){
		$htmls['edits'][]=array(
				'title'=>'下载APP',
				'list'=>array(
					array('type'=>'switch','title'=>'支持下载APP？','name'=>'app.isopen'),	
					array('type'=>'copy','title'=>'APP下载地址','name'=>'appurl','help'=>''),
					array('type'=>'ewm','title'=>'APP下载二维码','name'=>'appurl','help'=>''),
					array('type'=>'copy','title'=>'APP安装包地址','name'=>'app.installbak','help'=>'由平台总部统一上传'),
				)
		);
	}
	if($_SESSION['os']=='windows'){
		$return['htmls']=$htmls;
	}
	$citypeisong=plugin('jy_weishop')->plugin_setting('citypeisong');
	if($citypeisong['isopen']){
		$return['sendtypes']=array(
				'1'=>'同城配送',
				'2'=>'到店自取',
		);
	}else{
		$return['sendtypes']=array(
			'1'=>'快递配送',
			'2'=>'到店自取',
		);
	}
	$return['merch_type']=$this->merch_type;
	$return['account']=$_SESSION['account'];
	$return['extradata']=array();
	$return['cate']=pdo_getall('jy_merch_category',array('uniacid'=>$_SESSION['uniacid']),array('id','catename'));
	foreach($return['cate'] as $k=>&$gv){
		if($item['cateid']==$gv['id']){
			$item['pcateindex']=$k;
		}
	}
	$return['post']=$return['item']=$item;
	$return['myshop_tpls']=array(
		array('id'=>1,'title'=>'默认风格','image'=>'../addons/jy_merch/resource/images/tpl00.png'),
		array('id'=>2,'title'=>'小店风格','image'=>'../addons/jy_merch/resource/images/tpl01.png'),
	);
	if($_SESSION['os']=='mobile'){
		$return['htmls']=$this->template_url('manage/shop_index');
	}
	$return['province']=cfc('tools')->pcd();
	$return['credit_status']=array(0=>'不启用',1=>'启用交易',2=>'只显示不能交易');
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if($_SESSION['os']!='windows' &&  $_SESSION['container']!='wxapp' && $setting['is_smscode'] && !check_sms_code($postdata['smscode'])){
		exi('手机验证码错误！','error');
	}
	if(!$postdata['pcd']['city']){
		//exi('请选择商户城市','error');
	}
	if(!$postdata['merchname']){
		exi('商户名称必填','error');
	}
	if(!$postdata['lat_lng']){
		exi('请填写坐标！','error');
	}
	$merchid=pdo_getcolumn('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid),'id');
	if($postdata){
		//页面设计
		if($postdata['items']){
			foreach($postdata['items'] as &$v){
				if($v['extradata']){
					unset($v['extradata']);
				}
			}
		}
		$diypage=array(
			'items'=>$postdata['items']?ijson_encode($postdata['items']):'',
			'setting'=>$postdata['setting']?ijson_encode($postdata['setting']):''
		);
		if($diypage['items'] || $diypage['setting']){
			//检测恶意代码
			if(strexists($diypage['items'],'<?') || strexists($diypage['setting'],'<?')){
				exi('提交内容存在恶意代码，无法提交！','error');
			}
			//获取开发者自己的组件，并上传
			$local_blocks=pdo_getall('core_mobile_blocks',array('madehtml <>'=>''),array('cloud_id','default','madehtml'),'cloud_id');
			if($local_blocks){
					foreach($local_blocks as &$row){
						$row['madehtml']=cfc('files')->source_read($row['madehtml']);
						$row['default']=$row['default']?json_decode($row['default'],true):array();
					}
			}
			//设计完成后，对接云端生成页面
			$post=array('items'=>base64_encode($diypage['items']),'setting'=>base64_encode($diypage['setting']),'local_blocks'=>$local_blocks);
			$html=cloud_request('diy.mobile.made',$post);
			//将获得生成的html代码存入文件
			$merchuser=pdo_get('jy_merch_user',array('id'=>$merchid,'uniacid'=>$_SESSION['uniacid']),array('html'));
			$html=cfc('files')->source_save($html,'page','html','商户页面：'.$merchid,$merchuser['html']);
			if(!$merchuser['html']){
					$merchuser['html']=$html;
			}
		}
		$postdata['onewechat']['cert_file']=$postdata['cert_file'];
		$postdata['onewechat']['key_file']=$postdata['key_file'];
		$data =array(
			'type'=>intval($postdata['type']),
			'merchname'=>trim($postdata['merchname']),
			'topimg'=>trim($postdata['topimg']),
			'salecate'=>trim($postdata['salecate']),
			'desc'=>$postdata['desc'],
			'remark'=>$postdata['remark'],
			'logo'=>$postdata['logo'],
			'realname'=>trim($postdata['realname']),
			'mobile'=>trim($postdata['mobile']),
			'offline'=>intval($postdata['offline']),
			'onlinetime'=>ijson_encode($postdata['onlinetime']),
			'lat_lng'=>ijson_encode($postdata['lat_lng']),
			'address'=>trim($postdata['address']),
			'is_share'=>intval($postdata['is_share']),
			'iscommission'=>intval($postdata['iscommission']),
			'iskefu'=>intval($postdata['iskefu']),
			'myshop_tpl'=>intval($postdata['myshop_tpl']),
			'cateid'=>intval($postdata['cateid']),
			'star'=>intval($postdata['star']),
			'sudu'=>intval($postdata['sudu']),
			'isrecommand'=>$postdata['isrecommand'],
			'tel'=>$postdata['tel'],
			'out_pay'=>$postdata['out_pay'],
			'out_price'=>$postdata['out_price'],
			'man_fee'=>$postdata['man_fee'],
			'salenum'=>$postdata['salenum'],
			'groupid'=>$postdata['groupid'],
			'payopenid'=>$postdata['payopenid'],
			'isbrand'=>$postdata['isbrand'],
			'content'=>trim($postdata['content']),
			'mypeisong'=>$postdata['mypeisong'],
			'ismake'=>intval($postdata['ismake']),
			'codeimg'=>ijson_encode($postdata['codeimg']),
			'pcd'=>ijson_encode($postdata['pcd']),
			'out_juli'=>$postdata['out_juli'],
			'out_upfee'=>$postdata['out_upfee'],
			'opendiy'=>intval($postdata['opendiy']),
			'items'=>$diypage['items'],
			'setting'=>$diypage['setting'],
			'html'=>$merchuser['html'],
			'diyformdata'=>ijson_encode($postdata['diyfields']),
			'sendtype'=>intval($postdata['sendtype']),
			'sets'=>ijson_encode($postdata['sets']),
			'onewechat'=>ijson_encode($postdata['onewechat']),
			'onecredit'=>ijson_encode($postdata['onecredit']),
		);
		if($merchid){
			pdo_update('jy_merch_user',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['mid']=$_SESSION['uid'];
			$data['applytime']=time();
			pdo_insert('jy_merch_user',$data);
		}
		//添加客服
		$install = check_account_permission('jy_kefu');
		if($install){
			$member=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('nickname','avatar','mobile','groupid'));
			$kefuinfo=array(
				'nickname'=>trim($member['nickname']),
				'number'=>$postdata['mobile']?trim($postdata['mobile']):trim($member['mobile']),
				'picurl'=>trim($member['avatar']),
				'plugin'=>trim($member['plugin']),
				'pid'=>intval($merchid),
				'mid'=>$_SESSION['uid'],
			);
			$kefuinfo['type']=0;
			$kefuinfo['name']='kefu'.$_SESSION['uid'];
			model('jy_kefu/kefu')->add($kefuinfo);
			$kefuinfo['type']=1;
			$kefuinfo['name']='kefu1_'.$_SESSION['uid'];
			model('jy_kefu/kefu')->add($kefuinfo);
			$kefuinfo['type']=2;
			$kefuinfo['name']='kefu2_'.$_SESSION['uid'];
			model('jy_kefu/kefu')->add($kefuinfo);
		}else{
			//exi('无法开启客服，联系管理员开启<全网客服>','error');
		}
	}
	exi('设置成功','','goback');
}
if($_RQ['op']=='diy'){
	$item=pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid));
	$item['isdiy']=1;
    $return['plugin_icon']=$item['logo'];
	$item['lat_lng']=json_decode($item['lat_lng'],true);
	$item['codeimg']=json_decode($item['codeimg'],true);
	$item['onlinetime']=json_decode($item['onlinetime'],true);
	$item['sets']=json_decode($item['sets'],true);
	$item['onewechat']=json_decode($item['onewechat'],true);
	$item['onecredit']=json_decode($item['onecredit'],true);
	$item['pcd']=json_decode($item['pcd'],true);
	$item['diyformdata']=json_decode($item['diyformdata'],true);
	$item['myshop_tpl']=$item['myshop_tpl']?:0;
	$item['setting']=$item['setting'] && $item['setting']!='null'?json_decode($item['setting'],true):array('guide'=>array('title1'=>''));
	$return['status']=array('1'=>'开启','0'=>'关闭');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'DIY装修小店',
		'edit_tab'=>true,
		'edits'=>array(
				array(
					'title'=>'DIY装修小店',
					'list'=>array(
						array('type'=>'tip','title'=>'【温馨提示】：启用后DIY才生效！<red>有些组件《调用的》DIY时数据会不显示，但是真实预览会显示正常！</red>'),
						array('type'=>'switch','title'=>'启用DIY？','name'=>'opendiy','help'=>'开启后,DIY才生效！'),
						array('type'=>'diypage','title'=>'小店装修','name'=>'setting'),
					)
				),
			)
	);
	$return['htmls']=$htmls;
	//页面设计
	$return['used_navs']=array();
	$demoitems=array(
		array('nid'=>76,'params'=>array()),
		array('nid'=>77,'params'=>array()),
		array('nid'=>78,'params'=>array()),
	);
	$item['items']=$item['items'] && $item['items']!='null'?json_decode($item['items'],true):array();
	if(empty($item['items'][0]['nid'])){
		$item['items']=$demoitems;
	}
	if($item['items']){
			foreach($item['items'] as $row){
				if(!$return['used_navs'][$row['nid']]){
					$return['used_navs'][$row['nid']]=pdo_get('core_mobile_blocks',array('cloud_id'=>$row['nid']),array('name','showhtml','edithtml'));
				}
			}
	}
	$navs0=pdo_getall('core_mobile_blocks',array('type'=>0,'basictype'=>0,'support <>'=>2),array(),'','usenum desc',array('10'));
	if($navs0){
			foreach($navs0 as &$nav){
				$nav['default']=json_decode($nav['default'],true);
			}
	}
	$navs1=pdo_getall('core_mobile_blocks',array('type'=>0,'basictype'=>1,'support <>'=>2),array(),'','usenum desc',array('10'));
	if($navs1){
			foreach($navs1 as &$nav){
				$nav['default']=json_decode($nav['default'],true);
			}
	}	
	// 应用组件
	$pluginparams = array('type'=>1,'support <>'=>2);
	$plugins = plugin('jy_diypage')->plugins('jy_merch');
	if(!empty($plugins)){
			$pluginparams['plugin_id']=$plugins;
			$navs2=pdo_getall('core_mobile_blocks',$pluginparams,array(),'','usenum desc',array('10'));
			if($navs2){
				$plugintitles=array();
				$plugins=array();
				$i = 0;
				foreach($navs2 as $k=>&$nav){
					$plugintitle=pdo_getcolumn('core_plugins',array('name'=>$nav['plugin_id']),'title');
					$nav['default']=json_decode($nav['default'],true);
				if (!$plugintitle || in_array($plugintitle,$plugintitles)){
						
					}else{
						$plugintitles[$i] = $plugintitle;
						$plugins[$i]['name'] = $nav['plugin_id'];
						$plugins[$i]['plugintitle']=$plugintitle;
						$blocks = pdo_getall('core_mobile_blocks',array('type'=>1,'plugin_id'=>$nav['plugin_id']),array(),'','usenum desc',array('10'));
						foreach($blocks as &$b){
							$b['default']=json_decode($b['default'],true);
						}
						$plugins[$i]['navs'] = $blocks;
						$i  += 1;
					}
					
				}
			}
	}
	$return['navs0']=$navs0;
	$return['navs1']=$navs1;
	$return['navs2']=$plugins;
	$return['edit']=3;
	if(empty($item['setting']['bg'])){
		$item['setting']=array('top'=>array(),'footer'=>array());
	}
	$item['setting']['bg']=!empty($item['setting']['bg'])?:array('bg'=>'');
	$item['setting']['top']=!empty($item['setting']['top'])?:array();	
	$item['setting']['top']['title']=$item['setting']['top']['title']?:$item['title'];
	$return['menus']=pdo_getcolumn('core_diy_menu',array('uniacid'=>$_SESSION['uniacid'],'plugin'=>'core','status'=>1),'data');
	$return['menus']=json_decode($return['menus'],true);
	$item['setting']['footer']['menus']=!empty($item['setting']['footer']['menus']) ? $item['setting']['footer']['menus']:$return['menus']['menus'];
	$item['setting']['footer']['chosecolor']=$item['setting']['footer']['chosecolor']?:$_SESSION['customsyscolor'];
	$return['account']=$_SESSION['account'];
	$return['item']=$item;
	$return['extradata']=array();
	$return['cate']=pdo_getall('jy_merch_category',array('uniacid'=>$_SESSION['uniacid']),array('id','catename'));
	$return['myshop_tpls']=array(
		array('id'=>1,'title'=>'默认风格','image'=>'../addons/jy_merch/resource/images/tpl00.png'),
		array('id'=>2,'title'=>'小店风格','image'=>'../addons/jy_merch/resource/images/tpl01.png'),
	);
	if($_SESSION['os']=='mobile'){
		$return['htmls']=$this->template_url('manage/shop_index');
	}
	exi($return);
}
if($_RQ['op']=='openvoice'){
	$post=get_postdata();
	$isopenvoice=intval($_RQ['isopenvoice']);
	pdo_update('jy_merch_user',array('isopenvoice'=>$isopenvoice),array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid));
	exi('设置成功！');	
}